import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
      name: 'aaa',
      age: 18,
      height: 190,
      lists: [
        {text: 'a person',messages: 'male',boolean: true},
        {text: 'a person',messages: 'female',boolean: false},
      ]
    },
    mutations: {
        changeName(state,payload) {
            state.name = payload.name;
        }
    },
    getters: {
        getlists(state) {
            return state.lists.filter(list => list.boolean);
        },
        getCount(getters) {
            return getters.lists.length;
        }
    },
    actions: {
        editName(context,payload) {
            setTimeout(() => {
                context.commit('changeName',payload);
            }, 2000);
        }
    }
  })
  export default store
